package com.sujeet.activity.tracker.web;

import java.util.Date;
import java.util.Locale;
import java.text.DateFormat;

public class ParameterValueUtils {
	
	public static final String ESTIMATED_EFFORT = "estimatedEffort";
	public static final String ID = "id";
	public static final String START_DATE = "startDate";
	public static final String CHANGE_LOG = "changeLog";
	
	public static double getEstimatedEffort(String estimatedEffortString, double defaultVal) {
		double ret = defaultVal;
		try {
			ret = Double.parseDouble(estimatedEffortString);
		} catch (Exception e) {
			System.out.println("exception occured while converting Estimated Effort: " + estimatedEffortString + " " + e );
		}
		return ret;
	}
	
	public static int getId(String idString, int defaultVal) {
		int ret = defaultVal;
		try {
			ret = Integer.parseInt(idString);
		} catch (Exception e) {
			System.out.println("exception occured while converting Estimated Effort: " + idString + " " + e );
		}
		return ret;
	}
	
	public static Date getDate(String dateString, Date defaultVal) {
		Date ret = defaultVal;
		try {
			ret = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH).parse(dateString);
		} catch (Exception e) {
			System.out.println("Exception occured while parsing date: " + dateString + " " + e);
		}
		return ret;
	}
	
	public static String getChangeLog(String changeLog) {
		Date currDate = new Date();
		String ret = currDate.toString() + " :created " ;
		
		if (changeLog == null){
			return ret;
		} else {
			return currDate.toString() + " :" + changeLog;
		}		
	}
	
}
